<template>
    <div class="content">
      <nut-navbar class="navbar" z-index="5" :clickable="false" fixed safe-area-inset-top>
        <template #content>
          <span>{{ t(String(route.meta.title)) }}</span>
        </template>
        <template #left>
          <img src="/imgs/club/arrow_left.png" alt="" @click="router.go(-1)" class="arrow_left" />
        </template>
        <template #right>
          <span @click="router.push('/club/create')" class="save">创建</span>
        </template>
      </nut-navbar>

      <!-- 我创建的俱乐部 -->
      <h2 class="my_club_title">我创建的俱乐部</h2>
      <div class="club_list_box">
        <div class="club_list">
          <div v-for="club in clubs" :key="club.id" class="club_card">
            <div class="club_icon">
              <ImgT :src="club.icon" alt="club_icon" />
              <span class="badge" :class="club.roleClass">{{ club.role }}</span>
            </div>
            <div class="club_info">
              <h3 class="club_name">{{ club.name }}</h3>
              <p class="club_id">ID: {{ club.id }}</p>
              <p class="club_desc">{{ club.description }}</p>
            </div>
            <div class="club_action">
              <!-- <button @click="enterClub(club.id)" class="club_btn">
                {{ club.tables }}桌
              </button> -->
              <ImgT src="/imgs/club/arrow.png" class="arrow" alt="" />
            </div>
          </div>
        </div>
      </div>
      <!-- 我加入的俱乐部 -->
      <h2 class="my_club_title">我加入的俱乐部</h2>
      <div class="club_list_box">
        <div class="club_list">
          <div v-for="club in clubs" :key="club.id" class="club_card">
            <div class="club_icon">
              <ImgT :src="club.icon" alt="club_icon" />
              <span class="badge" :class="club.roleClass">{{ club.role }}</span>
            </div>
            <div class="club_info">
              <h3 class="club_name">{{ club.name }}</h3>
              <p class="club_id">ID: {{ club.id }}</p>
              <p class="club_desc">{{ club.description }}</p>
            </div>
            <div class="club_action">
              <!-- <button @click="enterClub(club.id)" class="club_btn">
                {{ club.tables }}桌
              </button> -->
              <ImgT src="/imgs/club/arrow.png" class="arrow" alt="" />
            </div>
          </div>
        </div>
      </div>

      <!-- 悬浮框 -->
      <LevitateBox
        @checkGame="onGameClick"
        @miniClick="onSwitchGameClick"
      />
    </div>
  </template>
  
  <script setup lang="ts">
  import { useI18n } from "vue-i18n";
  import { ref } from "vue";
  import {useRoute, useRouter} from "vue-router";

  import LevitateBox from '../components/levitateBox.vue';
  
  const route = useRoute();
  const router = useRouter();
  const { t } = useI18n();

  const clubs: any = ref([
    {
      id: 1223455,
      name: '天天王炸小伙伴',
      icon: '/imgs/club/culdlogo.png',
      role: '创建者',
      roleClass: 'creator',
      description: '俱乐部简介XXXXXXXXXXXXXXXX',
      tables: 1,
    },
    {
      id: 1223456,
      name: '天天王炸小伙伴',
      icon: '/imgs/club/culdlogo.png',
      role: '管理员',
      roleClass: 'admin',
      description: '俱乐部简介XXXXXXXXXXXXXXXX',
      tables: 1,
    },
    {
      id: 1223457,
      name: '天天王炸小伙伴',
      icon: '/imgs/club/culdlogo.png',
      role: '官方',
      roleClass: 'official',
      description: '俱乐部简介XXXXXXXXXXXXXXXX',
      tables: 1,
    },
    {
      id: 1223458,
      name: '天天王炸小伙伴',
      icon: '/imgs/club/culdlogo.png',
      role: '成员',
      roleClass: 'member',
      description: '俱乐部简介XXXXXXXXXXXXXXXX',
      tables: 1,
    },
  ]);

  const onGameClick = (item: any) => {
    console.log("Selected game:", item.label);
  }
  const onSwitchGameClick = (game: { id: number; title: string }) => {
    console.log(`你点击了游戏：${game.title}`);
  }
  </script>
  
  <style scoped lang="scss">
  .content {
    font-size: 14px;
    margin: 0 0 10px;

    .arrow_left {
      width: 24px;
      height: 24px;
    }

    .save {
      width: 56px;
      height: 32px;
      line-height: 32px;
      text-align: center;
      color: #FFFFFF;
      background: linear-gradient(180deg, #5567FF 0%, #9E1EFF 100%);
      box-shadow: 0.5px 0.5px 1px 0px #9B9EFF inset;
      border-radius: 8px;
    }
    .game_title {
      margin: 40px 0 12px 14px;
      img {
        width: 24px;
        height: 24px;
        display: inline-block;
        vertical-align: top;
      }
      span {
        color: #FFF;
        text-align: center;
        font-family: "PingFang SC";
        font-size: 16px;
        font-weight: 600;
      }
    }
    
    :deep(.nut-popup) {
      background: #131232B2;
    }
    
    .my_club_title {
      width: 347px;
      margin: 16px auto 8px;
      color: #FFFFFF;
      font-size: 14px;
      text-align: left;
    }

    .club_list_box {
      padding-left: 14px;

      .card_title {
        display: flex;
        padding: 0 14px;
        justify-content: space-between;
        align-items: center;
        height: 24px;
        line-height: 24px;
        margin: 12px 0;

        .title_left {
          font-family: PingFang SC;
          font-size: 14px;
          font-weight: 600;
          line-height: 16px;
          text-align: left;
          color: #FCFFFA;
          display: flex;
          justify-content: space-between;
          align-items: center;

          img {
            width: 18px;
            height: 18px;
            margin-right: 5px;
          }
        }

        .title_right {
          font-family: PingFang SC;
          font-size: 12px;
          font-weight: 500;
          line-height: 12px;
          text-align: left;
          color: #C6C4F5;
          display: flex;
          justify-content: space-between;
          align-items: center;

          .more {
            background: #282747;
            margin-left: 8px;
            padding: 8px;
            border-radius: 5px;
            box-shadow: 0.5px 0.5px 1px 0px #4B4A6E inset;
          }

          .swiper-btn {
            margin-left: 8px;
          }

          .disabled {
            pointer-events: none;
            opacity: 0.5;
            cursor: not-allowed;
          }
        }
      }

      .club_list {
        display: flex;
        flex-direction: column;
        gap: 10px;

        .club_card {
          width: 347px;
          height: 60px;
          display: flex;
          align-items: center;
          justify-content: space-around;
          border-radius: 10px;
          padding: 10px;
          color: white;
          background: url(/imgs/club/add_club_bg.png) no-repeat;
          background-size: 100% 100%;

          .club_icon {
            position: relative;
            width: 48px;
            height: 48px;
            margin-right: 8px;

            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }

            .badge {
              width: 48px;
              position: absolute;
              bottom: -5px;
              right: -5px;
              border-radius: 0 0 8px 8px;
              font-size: 12px;
              text-align: center;
              color: white;
              background: rgba(0, 0, 0, 0.6);
            }
          }
          .club_info {
            flex: 1;
            overflow: hidden;

            .club_name {
              font-size: 14px;
              font-weight: bold;
              margin: 0;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
            }

            .club_id,
            .club_desc {
              font-size: 12px;
              margin: 4px 0 0;
              font-family: PingFang SC;
              color: #AFB6BD;
            }
          }
          .club_action {
            display: flex;
            align-items: center;

            .club_btn {
              width: 40px;
              height: 20px;
              color: white;
              border: none;
              border-radius: 5px;
              font-size: 12px;
              line-height: 20px;
              background: #1DBA8B;
            }

            .arrow {
              width: 16px;
              height: 16px;
              margin-left: 10px;
              font-size: 18px;
              color: #FFFFFF;
            }
          }
        }
      }
    }

    .levitate_box {
      width: 72px;
      min-height: 72px;
      position: fixed;
      right: 15px;
      bottom: 86px;
      z-index: 99;
      li {
        margin: 6px 0;

        img {
          width: 72px;
          height: 72px;
        }
      }
      
    }
  }
  </style>
  